﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Venetasoft.WP.Net;

namespace BrewXML.WindowsPhone
{
    public partial class HomePage : PhoneApplicationPage
    {
        public HomePage()
        {
            InitializeComponent();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            this.MailPopup.IsOpen = true;
            this.ContentPanel.Visibility = Visibility.Collapsed;
        }
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
           // GerenateHtml();
            MailMessage mailMessage = new MailMessage();
            mailMessage.MailSent += mailMessage_MailSent;
            mailMessage.Progress += mailMessage_Progress;
            //set account
            mailMessage.UserName = this.txtUserName.Text.Trim();
            mailMessage.Password = this.txtPass.Password;
            if (mailMessage.UserName.Contains("@gmail"))
                mailMessage.AccountType = MailMessage.AccountTypeEnum.Gmail;
            else if (mailMessage.UserName.Contains("@live"))
                mailMessage.AccountType = MailMessage.AccountTypeEnum.MicrosoftAccount;
            //set emaildata
            mailMessage.To = this.txtToEmail.Text.Trim();
            mailMessage.Subject = "BeerXML Data";
            mailMessage.Body = "";
            //attachment
            
            mailMessage.AddAttachment("Grains.xml");
            mailMessage.AddAttachment("Hops.xml");
            mailMessage.AddAttachment("Miscs.xml");
            mailMessage.AddAttachment("Styles.xml");
            mailMessage.AddAttachment("Recipes.xml");
            mailMessage.Send();
        }
        void mailMessage_Progress(object sender, Venetasoft.WP7.ValueEventArgs<int> e)
        {
            try
            {
                this.txtProgress.Text = "Sending ";
            }
            catch (Exception)
            {


            }

        }

        void mailMessage_MailSent(object sender, Venetasoft.WP7.ValueEventArgs<bool> e)
        {
            if (e.Value == false)   //mail not sent         
            {
                this.txtProgress.Text = "Mail not sent";
            }
            else
            {
                // this.txtProgress.Text = "Successfully";
               
                MailPopup.IsOpen = false;
                this.ContentPanel.Visibility = Visibility.Visible;
            }
        }
        private void ButtonCancel_OnClick(object sender, RoutedEventArgs e)
        {
            this.MailPopup.IsOpen = false;
            this.ContentPanel.Visibility = Visibility.Visible;
        }
    }
}